package com.example.task1.ui.AllService.law;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.application.MyApplication;
import com.example.task1.bean.LawListBean;
import com.example.task1.bean.LawSortListBean;
import com.example.task1.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public class LawSortListAdapter extends BaseAdapter<LawSortListBean.RowsDTO> {

    private Context context;
    private List<LawSortListBean.RowsDTO> mData = new ArrayList<>();
    private TextView tvName;
    private ImageView image;
    private ImageView carImage;
    private TextView tvLegalExpertiseName;
    private TextView tvEduInfo;
    private TextView tvLicenseNo;
    private TextView tvWorkStartAt;
    private TextView tvServiceTimes;
    private TextView tvFavorableRate;

    public LawSortListAdapter(Context context) {
        this.context = context;
    }

    @Override
    protected void setData(List<LawSortListBean.RowsDTO> rows) {
        mData = rows;
        notifyDataSetChanged();
    }

    @Override
    protected int getLayout() {
        return R.layout.lawlist;
    }

    @Override
    protected Context getContext() {
        return null;
    }

    @Override
    protected List<LawSortListBean.RowsDTO> getData() {
        return mData;
    }

    @Override
    protected void onBind(myHolder holder, LawSortListBean.RowsDTO date) {
        MyApplication.glide(image, date.getAvatarUrl());
        MyApplication.glide(carImage, date.getCertificateImgUrl());
        tvEduInfo.setText("律师教育背景：" + date.getEduInfo());
        tvFavorableRate.setText("好评率：" + date.getFavorableRate());
        tvLegalExpertiseName.setText("擅长的法律专长名称：" + date.getLegalExpertiseName());
        tvName.setText(date.getName());
        tvWorkStartAt.setText("工作起始时间：" + date.getWorkStartAt());
        tvLicenseNo.setText("执业证编号：" + date.getLicenseNo());
        tvServiceTimes.setText("咨询人数：" + date.getServiceTimes());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyApplication.intent(context, LawDetailActivity.class, date.getId());
            }
        });
    }

    @Override
    protected void holder(View view) {
        initView(view);
    }

    private void initView(View view) {
        tvName = view.findViewById(R.id.tv_name);
        image = view.findViewById(R.id.image);
        carImage = view.findViewById(R.id.car_image);
        tvLegalExpertiseName = view.findViewById(R.id.tv_legalExpertiseName);
        tvEduInfo = view.findViewById(R.id.tv_eduInfo);
        tvLicenseNo = view.findViewById(R.id.tv_licenseNo);
        tvWorkStartAt = view.findViewById(R.id.tv_workStartAt);
        tvServiceTimes = view.findViewById(R.id.tv_serviceTimes);
        tvFavorableRate = view.findViewById(R.id.tv_favorableRate);
    }
}
